import java.util.Scanner;

class TreeNode {
    char val;
    TreeNode left;
    TreeNode right;

    TreeNode(char val) {
        this.val = val;
    }
}

public class BinaryTreeTraversal {
    private static int index = 0;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        while (scanner.hasNextLine()) {
            //trim用于去除首尾空白字符
            String input = scanner.nextLine().trim();

            if (input.isEmpty()) {
                System.out.println();
                continue;
            }

            index = 0;
            TreeNode root = buildTree(input);
            //用于需频繁拼接的字符串
            StringBuilder result = new StringBuilder();
            inorderTraversal(root, result);
            System.out.println(result);
        }
        scanner.close();
    }

    private static TreeNode buildTree(String s) {
        //有空返回上节点的右子节点（先序）
        if (index >= s.length() || s.charAt(index) == '#') {
            //空节点已经历，故++
            index++;
            return null;
        }

        TreeNode node = new TreeNode(s.charAt(index++));
        node.left = buildTree(s);
        node.right = buildTree(s);
        return node;
    }

    //中序遍历
    private static void inorderTraversal(TreeNode node, StringBuilder result) {
        if (node == null) {
            return;
        }

        inorderTraversal(node.left, result);
        //append用于为此类 动态添加内容

        //先会在左子节点为空的父节点运行
        //逐步返回并判定右节点
        //后再逐步回退到根节点
        //最后遍历右半部分     
        result.append(node.val).append(" ");
        inorderTraversal(node.right, result);
    }
}
//输入:abc##de#g##f###
//输出:c b e g d f a